package com.teach.servlet.admin;

import com.teach.dao.CountryInfoDAO;
import com.teach.dao.impl.CountryInfoDAOImpl;
import com.teach.entity.CountryInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <pre>
 * - 参赛国家列表(json)
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2022-05-05 11:30
 * Version : 1.0
 * Copyright 2022 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
@WebServlet("/admin/country-delete.let")
public class CountryDeleteServlet extends HttpServlet {

  private CountryInfoDAO dao = new CountryInfoDAOImpl();

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    response.reset();
    response.setContentType("application/json;charset=UTF-8");
    try {

      String code = request.getParameter("countryCode");

      try {
        dao.deleteById(code);
        response.getWriter().print("{\"ok\":true}");
      } catch (Exception ex) {
        throw new ServletException("删除失败", ex);
      }

    }catch (Exception ex){
      response.getWriter().print("{\"ok\":false,\"msg\":\""+ex.getMessage()+"\"}");
    }

    response.flushBuffer();
  }
}
